home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Moof / Goodies / HyperCard Goodies / HyperCard Dev. ToolKit / Serial & MacinTalk XCMDs / sendPort.p < prev    next >
Text File  |  1987-07-15  |  2KB  |  93 lines

  1. {$R-}
  2.  
  3. (*
  4.     sendSPort portNumber, addLFs, string -- Send a string to the serial port driver.
  5.  
  6.     To compile and link this file using Macintosh Programmer's Workshop,
  7.  
  8.     pascal -w sendPort.p
  9.     link -m ENTRYPOINT -o HyperCommands -rt XCMD=2 -sn Main=sendSPort sendPort.p.o "{MPW}"Libraries:interface.o
  10.     
  11. *)
  12.  
  13. {$S sendSPort }     { Segment name must be the same as the command name. }
  14.  
  15. unit DummyUnit;
  16.  
  17. interface
  18.  
  19. uses MemTypes, QuickDraw, OSIntf, HyperXCmd;
  20.  
  21. procedure EntryPoint(paramPtr: XCmdPtr);
  22.     
  23. implementation
  24.  
  25. const
  26.  
  27. return = 13;
  28. linefeed = 10;
  29.  
  30. type
  31.  
  32. Str31 = String[31];
  33.  
  34. procedure sendSPort(paramPtr: XCmdPtr); forward;
  35.  
  36. procedure EntryPoint(paramPtr: XCmdPtr);
  37.  
  38.     begin
  39.         sendSPort(paramPtr);
  40.     end;
  41.  
  42. procedure sendSPort(paramPtr: XCmdPtr);
  43.  
  44.     var portNumber: integer;
  45.         outPort: integer;
  46.         sendLFs: boolean;
  47.         str: Str255;
  48.         p: Ptr;
  49.         l: longInt;
  50.         linefeedByte: SignedByte;
  51.  
  52.     {$I XCmdGlue.inc}
  53.  
  54.     procedure Fail(errMsg: Str255); { set theResult and quit }
  55.         begin
  56.             paramPtr^.returnValue := PasToZero(errMsg);
  57.             exit(sendSPort);
  58.         end;
  59.  
  60.     begin
  61.         if paramPtr^.paramCount <> 3 then Fail('parameter count is not 3');
  62.  
  63.         ZeroToPas(paramPtr^.params[1]^,str);        { First parameter is port number. }
  64.         portNumber := StrToNum(str);
  65.         if (portNumber < 1) or (portNumber > 2) then Fail('invalid port number');
  66.         ZeroToPas(paramPtr^.params[2]^,str);        { Third parameter is whether to wait. }
  67.         sendLFs := false;
  68.         if length(str) > 0 then
  69.             if (str[1] = 't') or (str[1] = 'T') then sendLFs := true;
  70.         HLock(paramPtr^.params[3]);
  71.         p := paramPtr^.params[3]^;        { Second parameter is string to send. }
  72.  
  73.         if portNumber = 1 then outPort := -7
  74.         else outPort := -9;
  75.         linefeedByte := linefeed;
  76.         while p^ <> 0 do
  77.             begin
  78.                 l := 1;
  79.                 if FSWrite(outPort,l,p) <> noErr then Fail('FSWrite failed');
  80.                 if l <> 1 then Fail('not all characters sent');
  81.                 if sendLFs and (p^ = return) then
  82.                     begin
  83.                         l := 1;
  84.                         if FSWrite(outPort,l,@linefeedByte) <> noErr then Fail('FSWrite failed');
  85.                         if l <> 1 then Fail('not all characters sent');
  86.                     end;
  87.                 p := ptr(ord4(p)+1);
  88.             end;
  89.         HUnlock(paramPtr^.params[3]);
  90.     end;
  91.  
  92. end.
  93.